import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';

const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        name: 'Home',
        redirect: '/home',
        meta: {
            auth: true,
            title:''
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/home/index.vue'),
        children: [
            {
                path: '/home',
                name: 'Home',
                meta: {
                    title: '首页',
                    menu: 'Home',
                },
                component: () => import(/* webpackChunkName: "Home" */ '../views/home/mall/Home/index.vue')
            },
            {
                path: '/live',
                name: 'Live',
                meta: {
                    title: '直播管理',
                    menu: 'Live',
                },
                component: () => import(/* webpackChunkName: "mall" */ '../views/home/mall/Live/index.vue'),
            },
            {
                path: '/live-create',
                name: 'LiveCreate',
                meta: {
                    title: '直播',
                    menu: 'Live',
                    more: true
                },
                component: () => import(/* webpackChunkName: "mall" */ '../views/home/mall/Live/create.vue'),
            },
            {
                path: '/live-detail',
                name: 'LiveDetail',
                meta: {
                    title: '直播管理',
                    menu: 'Live',
                    more: true
                },
                component: () => import(/* webpackChunkName: "mall" */ '../views/home/mall/Live/detail.vue'),
            },
            {
              path: '/onDemand',
              name:'OnDemand',
              meta: {
                  menu:'OnDemand',
                  title:'点播管理',
              },
              component: () =>
                  import(
                      /* webpackChunkName: "tool" */ '../views/home/mall/OnDemand/index.vue'
                  )
            },
            {
                path: '/onDemand-detail',
                name: 'OnDemandDetail',
                meta: {
                    title: '点播管理',
                    menu: 'OnDemand',
                    more: true
                },
                component: () => import(/* webpackChunkName: "mall" */ '../views/home/mall/OnDemand/detail.vue'),
            },
            {
                path: '/onDemand-create',
                name: 'OnDemandCreate',
                meta: {
                    title: '点播管理',
                    menu: 'OnDemand',
                    more: true
                },
                component: () => import(/* webpackChunkName: "mall" */ '../views/home/mall/OnDemand/create.vue'),
            },
            {
                path: '/manufacturer',
                name: 'Manufacturer',
                meta: {
                    title: '厂商管理',
                    menu: 'Manufacturer',
                },
                component: () => import(/* webpackChunkName: "mall" */ '../views/home/mall/Manufacturer/index.vue')
            },
            {
                path: '/manufacturer-detail',
                name: 'ManufacturerDetail',
                meta: {
                    title: '厂商管理',
                    menu: 'Manufacturer',
                    more: true,
                },
                component: () => import(/* webpackChunkName: "mall" */ '../views/home/mall/Manufacturer/detail.vue'),
            },
            {
                path: '/user',
                name: 'User',
                meta: {
                    title: '用户管理',
                    menu: 'User',
                },
                component: () => import(/* webpackChunkName: "mall" */ '../views/home/mall/User/index.vue')
            },
        ]
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import(/* webpackChunkName: "Login" */ '../views/login/index.vue')
    },
    {
        path: '/notfind',
        name: 'Notfind',
        component: () => import(/* webpackChunkName: "Notfind" */ '../views/notfind/index.vue')
    },
    {
        path: '/:pathMath(.*)',
        redirect: '/notfind'
    }
];

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
});
router.beforeEach((to, form, next) => {
    if (to.meta.auth) {
        if(sessionStorage.getItem('PW')) {
            next();
        } else {
            next({ path: '/login' });
        }
    } else {
        next();
    }
});

export default router;
